from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains

class Base:
    #驱动
    def __init__(self,driver):
        self.driver=driver

    #打开网址
    def open_url(self,url):
        self.driver.get(url)

    #定位元素
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)

        except Exception as e:
            print(e)

    #点击
    def click(self,loc):
        self.find_element(loc).click()

    #输入内容
    def send_keys(self,loc,info):


        self.find_element(loc).send_keys(info)

    #文本
    def text(self,loc):
        return self.find_element(loc).text

    #悬停
    def move_to(self,loc):
        ActionChains(self.driver).move_to_element(loc).perform()

    #双击
    def double_click(self,loc):
        ActionChains(self.driver).double_click(loc).perform()

    #Iframe
    def Iframe(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))

    #拖拽
    def drag_and_drop(self,loc,a,b):
        ActionChains(self.driver).drag_and_drop(a,b)

    #下拉框
    def select(self,loc,value):
        Select(self.find_element(loc)).select_by_value(value)

    #清除数据
    def clear(self,loc):
        self.find_element(loc).clear()
